﻿Imports System
Imports System.CodeDom
Imports System.Collections.Generic
Imports System.Diagnostics.CodeAnalysis
Imports System.Reflection

Namespace System.Workflow.Activities.Rules
    Public Class RuleAnalysis
        ' Methods
        Public Sub New(ByVal validation As RuleValidation, ByVal forWrites As Boolean)
            Me.validation = validation
            Me.forWrites = forWrites
        End Sub

        Public Sub AddSymbol(ByVal symbol As String)
            Me.symbols.Item(symbol) = Nothing
        End Sub

        Friend Sub AnalyzeRuleAttributes(ByVal member As MemberInfo, ByVal targetExpr As CodeExpression, ByVal targetQualifier As RulePathQualifier, ByVal argExprs As CodeExpressionCollection, ByVal parameters As ParameterInfo(), ByVal attributedExprs As List([Of] CodeExpression))
            Dim customAttributes As Object() = member.GetCustomAttributes(GetType(RuleAttribute), True)
            If ((Not customAttributes Is Nothing) AndAlso (customAttributes.Length > 0)) Then
                Dim attributeArray As RuleAttribute() = DirectCast(customAttributes, RuleAttribute())
                Dim i As Integer
                For i = 0 To attributeArray.Length - 1
                    attributeArray(i).Analyze(Me, member, targetExpr, targetQualifier, argExprs, parameters, attributedExprs)
                Next i
            End If
        End Sub

        <SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")> _
        Public Function GetSymbols() As ICollection([Of] String)
            Dim list As New List([Of] String)(Me.symbols.Keys.Count)
            Dim pair As KeyValuePair([Of] String, Object)
            For Each pair In Me.symbols
                list.Add(pair.Key)
            Next
            Return list
        End Function


        ' Properties
        Public ReadOnly Property ForWrites As Boolean
            Get
                Return Me.forWrites
            End Get
        End Property

        Friend ReadOnly Property Validation As RuleValidation
            Get
                Return Me.validation
            End Get
        End Property


        ' Fields
        Private forWrites As Boolean
        Private symbols As Dictionary([Of] String, Object) = New Dictionary([Of] String, Object)
        Private validation As RuleValidation
    End Class
End Namespace

